import { handleActions } from "redux-actions";
import { GET_ALL,SET_CUR_PAGE,SET_EACH_PAGE } from "../types.js";
import _ from "lodash";

// 初始化数据
const InitData = {
    curPage: 1,
    eachPage: 10,
    total: 0,
    maxPage: 0,
    rows: [],
}

export const getAll = handleActions({
    // 获取所有类型
    [GET_ALL]: (state, { payload }) => {
        const { total, maxPage, rows } = payload;
        return _.assign({}, state, {
            total, maxPage, rows
        })
    },
    [SET_CUR_PAGE]: (state, { payload }) => {
        const {curPage}=payload
        const $state=_.clone(state);
        $state.curPage=curPage
        return $state;
    },
    [SET_EACH_PAGE]: (state, { payload }) => {
        const {eachPage}=payload
        const $state=_.clone(state);
        $state.eachPage=eachPage
        return $state;
    },
}, InitData)